home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscProgressPalette / MiscProgressView.subproj / MiscProgressView.m < prev    next >
Text File  |  1995-04-12  |  3KB  |  170 lines

  1. //
  2. //    MiscProgressView.m -- a simple view class for displaying progress
  3. //        Written originally by Don Yacktman Copyright (c) 1993 by James Heiser.
  4. //                Modified from an example in the NeXT documentation.
  5. //                This file is maintained by James Heiser, jheiser@adobe.com.
  6. //                Version 1.0.  All rights reserved.
  7. //
  8. //        This notice may not be removed from this source code.
  9. //
  10. //    This object is included in the MiscKit by permission from the author
  11. //    and its use is governed by the MiscKit license, found in the file
  12. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  13. //    for a list of all applicable permissions and restrictions.
  14. //    
  15.  
  16. #import "MiscProgressView.h"
  17.  
  18. @implementation MiscProgressView
  19.  
  20. - initFrame:(const NXRect *)frameRect
  21. {
  22.     [super initFrame:frameRect];
  23.     bg = NXConvertGrayToColor(NX_LTGRAY);
  24.     fg = NXConvertGrayToColor(NX_DKGRAY);
  25.     bd = NXConvertGrayToColor(NX_BLACK);
  26.     total = MISC_PROGRESS_MAXSIZE;
  27.     stepSize = MISC_PROGRESS_DEFAULTSTEPSIZE;
  28.     count = 0;
  29.     ratio = 0.0;
  30.     return self;
  31. }
  32.  
  33. - renderBackground
  34. {
  35.     NXSetColor(bg);
  36.     NXRectFill(&bounds);
  37.     return self;
  38. }
  39.  
  40. - renderBar
  41. {
  42.     if ((ratio > 0) && (ratio <= 1.0)) {
  43.         NXRect r = bounds;
  44.         r.size.width = bounds.size.width * ratio;
  45.         NXSetColor(fg);
  46.         NXRectFill(&r);
  47.     }
  48.     return self;
  49. }
  50.  
  51. - renderBorder
  52. {
  53.     NXSetColor(bd);
  54.     NXFrameRect(&bounds);
  55.     return self;
  56. }
  57.  
  58.  
  59. - drawSelf:(const NXRect *)rects :(int)rectCount
  60. { // Note from Don on why this -drawSelf: is split up --
  61. // The three separate rendering methods make things a little less efficient,
  62. // but make it a lot easier to subclass and retain parts of the original
  63. // rendering.  I wish NeXT had done something like this with the various
  64. // control classes so that subclasses could override parts of the steps
  65. // in the rendering process...or insert things at certain points in time.
  66.     [self renderBackground];
  67.     [self renderBar];
  68.     [self renderBorder];
  69.     return self;
  70. }
  71.  
  72. - setStepSize:(int)value
  73. {
  74.     stepSize = value;
  75.     return self;
  76. }
  77.  
  78. - (int)stepSize { return stepSize; }
  79. - (NXColor)backgroundColor { return bg; }
  80. - (NXColor)foregroundColor { return fg; }
  81. - (NXColor)borderColor { return bd; }
  82.  
  83. - setBackgroundColor:(NXColor)color
  84. {
  85.     bg = color;
  86.     return self;
  87. }
  88.  
  89. - setForegroundColor:(NXColor)color
  90. {
  91.     fg = color;
  92.     return self;
  93. }
  94.  
  95. - setBorderColor:(NXColor)color
  96. {
  97.     bd = color;
  98.     return self;
  99. }
  100.  
  101. - setRatio:(float)newRatio
  102. {
  103.     if (newRatio > 1.0) newRatio = 1.0;
  104.     if (ratio != newRatio) {
  105.         ratio = newRatio;
  106.         [self display];
  107.     }
  108.     return self;
  109. }
  110.  
  111.  
  112. - takeIntValueFrom:sender
  113. {
  114.     int temp = [sender intValue];
  115.     if ((temp < 0) || (temp > total)) return nil;
  116.     count = temp;
  117.     [self setRatio:(float)count/(float)total];
  118.     return self;
  119. }
  120.  
  121. - increment:sender
  122. {
  123.     count += stepSize;
  124.     [self setRatio:(float)count/(float)total];
  125.     return self;
  126. }
  127.  
  128. - takeFloatValueFrom:sender
  129. {
  130.     [self setRatio:[sender floatValue]];
  131.     count = ceil(ratio * (float)total);
  132.     return self;
  133. }
  134.  
  135. - (const char *)getInspectorClassName
  136. {
  137.     return "MiscProgressViewInspector";
  138. }
  139.  
  140. - clear:sender
  141. {
  142.     count = 0;
  143.     [self setRatio: 0];
  144.     return self;
  145. }
  146.  
  147.  
  148. - read:(NXTypedStream *)stream
  149. {
  150.     [super read:stream];
  151.     NXReadTypes(stream, "ii", &total, &stepSize);
  152.     bg = NXReadColor(stream);
  153.     fg = NXReadColor(stream);
  154.     bd = NXReadColor(stream);
  155.     return self;
  156. }
  157.  
  158. - write:(NXTypedStream *)stream
  159. {
  160.     [super write:stream];
  161.     NXWriteTypes(stream, "ii", &total, &stepSize);
  162.     NXWriteColor(stream, bg);
  163.     NXWriteColor(stream, fg);
  164.     NXWriteColor(stream, bd);
  165.     return self;
  166. }
  167.  
  168.  
  169. @end
  170.